import random
from time import sleep
import uiautomation
import pyautogui

from tools.sjqd_way import write_data_from_excel


class zhuyuandengji():
        name = random.randrange(1,101)
        sex = random.choice(['男','女'])
        age = random.randrange(10, 71)
        tel = random.randrange(00000000,99999999)
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()
        jibenxinxizu = his.GroupControl(ClassName='GroupBox',Name='基本信息')
        bingrenfeibie = jibenxinxizu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox')
        xingming = jibenxinxizu.EditControl(AutomationId='txtName',ClassName='TextBox')
        xingbie = jibenxinxizu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=2)
        nianling  = jibenxinxizu.EditControl(AutomationId='tbNianling',ClassName='TextBox')
        yiliaofufeifangshi = jibenxinxizu.ComboBoxControl(ClassName='ComboBox',foundIndex=3)
        zhu = his.GroupControl(ClassName='GroupBox',Name='')
        ruyuanbingqu = zhu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=1)
        ruyuankeshi = zhu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=2)
        ruyuantujing = zhu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=3)
        zhenduanzhu = his.GroupControl(ClassName='GroupBox',Name='诊断')
        xiyijibing = zhenduanzhu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=2)
        jiatingdizhizhu = his.GroupControl(ClassName='GroupBox',Name='家庭地址(现住址)')
        xiangxidizhi = jiatingdizhizhu.EditControl(ClassName='TextBox',foundIndex=5)
        dianhua = jiatingdizhizhu.EditControl(ClassName='TextBox',foundIndex=6)
        quedinganniu = his.ButtonControl(AutomationId='confirm_btn',ClassName='Button',Name='确定')
        zhuyuandengjichuangkou = his.WindowControl(AutomationId='registrationWin',ClassName='Window',Name='住院登记')
        tishiqueding = his.ButtonControl(AutomationId='confirm_btn',ClassName='Button',Name='确定')
        tishiquxiao = his.ButtonControl(ClassName='Button',Name='取消')

        #输入病人费别
        def input_brfb(self,brfb):
                self.bingrenfeibie.Click()
                self.bingrenfeibie.SendKeys(brfb)
                sleep(1)
                pyautogui.press('enter')

        #输入患者姓名
        def input_xm(self):
                self.xingming.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.press('back')
                self.xingming.SendKeys('住院测试患者{}'.format(self.name))
                ceshihuanzhe = self.xingming.GetValuePattern().Value
                write_data_from_excel(ceshihuanzhe)

        #选择患者性别
        def choose_xb(self):
                self.xingbie.Click()
                self.xingbie.SendKeys('{}'.format(self.sex))
                sleep(1)
                pyautogui.press('enter')

        # 输入年龄
        def input_age(self):
                self.nianling.SendKeys('{}'.format(self.age))

        #选择医疗付费方式
        def choose_fffs(self,fffs):
                self.yiliaofufeifangshi.Click()
                self.yiliaofufeifangshi.SendKeys(fffs)
                pyautogui.press('enter')

        #选择入院病区
        def input_rybq(self,rybq):
                self.ruyuanbingqu.Click()
                self.ruyuanbingqu.SendKeys(rybq)
                sleep(1)
                pyautogui.press('enter')

        #选择入院科室
        def input_ryks(self,ryks):
                self.ruyuankeshi.Click()
                self.ruyuankeshi.SendKeys(ryks)
                sleep(1)
                pyautogui.press('enter')

        #选择入院途径
        def input_rytj(self,rytj):
                self.ruyuantujing.Click()
                self.ruyuantujing.SendKeys(rytj)
                sleep(1)
                pyautogui.press('enter')

        #选择西医疾病
        def input_xyjb(self,xyjb):
                self.xiyijibing.Click()
                self.xiyijibing.SendKeys(xyjb)
                sleep(1)
                pyautogui.press('enter')

        #输入详细地址
        def input_address(self,adress):
                self.xiangxidizhi.SendKeys(adress)
        #输入电话号码
        def input_num(self):
                self.dianhua.SendKeys('134{}'.format(self.tel))

        #点击确定按钮
        def click_qd_btn(self):
                self.quedinganniu.Click()

        #点击确定按钮
        def click_tsqd_btn(self):
                self.tishiqueding.Click()
        #点击取消按钮
        def cliick_tsqx_btn(self):
                self.tishiquxiao.Click()

        def creat_zyhz(self,brfb,fffs,rybq,ryks,rytj,xyjb,xxdz):
                self.bingrenfeibie.Click()
                self.bingrenfeibie.SendKeys(brfb)
                sleep(1)
                pyautogui.press('enter')
                self.xingming.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.press('back')
                self.xingming.SendKeys('住院测试患者{}'.format(self.name))
                ceshihuanzhe = self.xingming.GetValuePattern().Value
                write_data_from_excel(ceshihuanzhe)
                self.xingbie.Click()
                self.xingbie.SendKeys('{}'.format(self.sex))
                sleep(1)
                pyautogui.press('enter')
                self.nianling.SendKeys('{}'.format(self.age))
                self.yiliaofufeifangshi.Click()
                self.yiliaofufeifangshi.SendKeys(fffs)
                pyautogui.press('enter')
                self.ruyuanbingqu.Click()
                self.ruyuanbingqu.SendKeys(rybq)
                sleep(1)
                pyautogui.press('enter')
                self.ruyuankeshi.Click()
                self.ruyuankeshi.SendKeys(ryks)
                sleep(1)
                pyautogui.press('enter')
                self.ruyuantujing.Click()
                self.ruyuantujing.SendKeys(rytj)
                sleep(1)
                pyautogui.press('enter')
                self.xiyijibing.Click()
                self.xiyijibing.SendKeys(xyjb)
                sleep(1)
                pyautogui.press('enter')
                self.xiangxidizhi.SendKeys(xxdz)
                self.dianhua.SendKeys('134{}'.format(self.tel))
                self.quedinganniu.Click()
                self.tishiquxiao.Click()









